;(function($) {
	/**
	 * 浮点数四则运算
	 * @example $.calcFloat.plus(0.1, 0.2);
	 */
	$.calcFloat = {
        plus: addition,
        minus: subtraction,
        times: multiply,
        divide: division
	};

	// 加
    function addition(a, b) {
        var c, d, e, f;
        try {
            c = a.toString().split('.')[1].length;
        } catch (err) {
            c = 0;
        }
        try {
            d = b.toString().split('.')[1].length;
        } catch (err) {
            d = 0;
        }
        e = Math.pow(10, Math.max(c, d));
        f = (multiply(a, e) + multiply(b, e)) / e;
        return (f.toFixed(c > d ? c : d));
    }

    // 减
    function subtraction(a, b) {
        var c, d, e, f;
        try {
            c = a.toString().split('.')[1].length;
        } catch (err) {
            c = 0;
        }
        try {
            d = b.toString().split('.')[1].length;
        } catch (err) {
            d = 0;
        }
        e = Math.pow(10, Math.max(c, d));
        f = (multiply(a, e) - multiply(b, e)) / e;
        return (f.toFixed(c > d ? c : d));
    }

    // 乘
    function multiply(a, b) {
        var c = 0, d = a.toString(), e = b.toString();
        try {
            c += d.split('.')[1].length;
        } catch (err) {}
        try {
            c += e.split('.')[1].length;
        } catch (err) {}
        return Number(d.replace('.', '')) * Number(e.replace('.', '')) / Math.pow(10, c);
    }

    // 除
    function division(a, b) {
        var c, d, e = 0, f = 0;
        try {
            e = a.toString().split('.')[1].length;
        } catch (err) {}
        try {
            f = b.toString().split('.')[1].length;
        } catch (err) {}
        c = Number(a.toString().replace('.', ''));
        d = Number(b.toString().replace('.', ''));
        return multiply(c / d, Math.pow(10, f - e));
    }
})(jQuery);
